package com.medical.data.controller;


import com.aliyuncs.exceptions.ClientException;
import com.medical.data.domain.FormTemplate;
import com.medical.data.service.FollowPatientService;
import com.medical.data.service.FollowUpPatientService;
import com.medical.data.service.SmsSendService;
import com.medical.data.utils.Result;
import com.medical.data.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cj
 * @since 2024-02-06
 */
@RestController
@RequestMapping("/data/followUpPatient")
@Api(description = "随访管理")
@Slf4j
public class FollowUpPatientController {
/*    @Autowired
    private FollowUpPatientService followUpPatientService;*/
    @Autowired
    private FollowPatientService followPatientService;

    @Autowired
    private SmsSendService smsSendService;

    @ApiOperation("随访日历")
    @PostMapping("/getPatientByData")
    public Result getPatientByData(@Validated @RequestBody GetPatientByDataVo getPatientByDataVo) {
        log.info("/data/followUpPatient/getFollowNumberByDay参数========>{}", getPatientByDataVo);
        Map<String, Object> map=followPatientService.getPatientByDate(getPatientByDataVo);
        return Result.ok().data("patient",map);
    }

    @ApiOperation("获取某一天的随访患者")
    @PostMapping("/getPatient")
    public Result getPatient(@Validated @RequestBody FollowUpDay followUpDay) {
        log.info("/data/followUpPatient/getPatient参数========>{}", followUpDay);
        Map<String,Object>map=followPatientService.getPatientByDay(followUpDay);
        return Result.ok().data("dayPatient",map);
    }

    @ApiOperation("获取随访概况")
    @PostMapping("/getPatientStatus")
    public Result getPatientStatus() {
        log.info("/data/followUpPatient/getPatientStatus参数========>{}");
        Map<String,Object>map=followPatientService.getPatientStatus();
        return Result.ok().data("patientStatus",map);
    }

    @ApiOperation("短信提醒随访，传id，不是患者id")
    @PostMapping("/sendMessage/{id}")
    public Result testSendSms2(@PathVariable String id) throws ClientException{
        log.info("/data/followUpPatient/sentMessage参数========>{}",id);
        smsSendService.testSendSms2(id);
        return Result.ok();
    }

    @ApiOperation("短信提醒随访，传患者id")
    @PostMapping("/getFollowUpData/{id}/{nodeId}")
    public Result getFollowUpData(@PathVariable String id,@PathVariable String nodeId){
        log.info("/data/followUpPatient/getFollowUpData参数========>{}",id,nodeId);
        FollowDataVo followDataVo=followPatientService.getFollowUpData(id,nodeId);
        return Result.ok().data("data",followDataVo);
    }
}

